Don't make it easy to iterate the state_t enum...except when we do. (#939)
authorRobert Lipe <robertlipe@users.noreply.github.com>
Sun, 30 Oct 2022 03:45:20 +0000 (22:45 -0500)
committerGitHub <noreply@github.com>
Sun, 30 Oct 2022 03:45:20 +0000 (22:45 -0500)
brauniger_iq.cc

index 71c790c1bc03886f46ea2dbf9b9f67cafee9e572..7074caac2ddc835587d844126fbd5649521ea87f 100644 (file)
@@ -48,18 +48,8 @@ namespace { // fix ODR violation with igc
     num_states
   };
 }
-static state_t state;
-inline state_t& operator++(state_t& s) // prefix
-{
-  return s = static_cast<state_t>(s + 1);
-}
-inline state_t operator++(state_t& s, int) // postfix
-{
-  state_t ret(s);
-  ++s;
-  return ret;
-}
 
+static state_t state;
 static const int reqd_bytes[num_states] = { 6, 1, 2, 2, 25, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1 };
 
 static void rd_init(const QString& fname)
@@ -227,7 +217,12 @@ static int process_data(const unsigned char* data)
   default:
     fatal(MYNAME ": Bad internal state\n");
   }
-  ++state;
+
+  // Iterating an enum isn't great and it's less greatr that reqd_byte[] is
+  // implicitly coupled to our state_t, but here we are with C code forged
+  // into C++.
+  state = static_cast<state_t> (state + 1);
+
   return remaining;
 }